package com.gary.security.model;

import java.io.Serializable;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import com.gary.core.model.BaseModel;

public class UserInfo extends BaseModel implements Serializable {
    // ----------------------------------------------------
    // static fields
    // ----------------------------------------------------
    /** * serial. */
    static final long serialVersionUID = 0L;

    /** * 可用状态. */
    public static final Integer STATUS_ENABLED = Integer.valueOf(1);

    /** * 不可用状态. */
    public static final Integer STATUS_DISABLED = Integer.valueOf(0);

    /** * 状态枚举. */
    public static final Map<Integer, String> STATUS_ENUM = new LinkedHashMap<Integer, String>();

    static {
        STATUS_ENUM.put(STATUS_ENABLED, "有效");
        STATUS_ENUM.put(STATUS_DISABLED, "无效");
    }

    /** * dept. */
    private DeptInfo dept;
    
    private String loginId;

    /** * username. */
    private String username;

    /** * password. */
    private String password;

    /** * status. */
    private Integer status;

    /** * descn. */
    private String descn;

    /** * roles. */
    private Set<RoleInfo> roles = new HashSet<RoleInfo>(0);

    /** * 构造方法. */
    public UserInfo() {
    }
    
    public DeptInfo getDept() {
        return dept;
    }

    /** * @param dept dept. */
    public void setDept(DeptInfo dept) {
        this.dept = dept;
    }

    /** * @return username. */
    public String getUsername() {
        return username;
    }

    /** * @param username username. */
    public void setUsername(String username) {
        this.username = username;
    }
    
    /** * @return loginId. */
    public String getLoginId() {
        return loginId;
    }

    /** * @param loginId loginId. */
    public void setLoginId(String loginId) {
        this.loginId = loginId;
    }

    /** * @return password. */
    public String getPassword() {
        return password;
    }

    /** * @param password password. */
    public void setPassword(String password) {
        this.password = password;
    }

    /** * @return status. */
    public Integer getStatus() {
        return status;
    }

    /** * @param status status. */
    public void setStatus(Integer status) {
        this.status = status;
    }

    /** * @return descn. */
    public String getDescn() {
        return descn;
    }

    /** * @param descn descn. */
    public void setDescn(String descn) {
        this.descn = descn;
    }

    /** * @return roles. */
    public Set<RoleInfo> getRoles() {
        return roles;
    }

    /** * @param roles roles. */
    public void setRoles(Set<RoleInfo> roles) {
        this.roles = roles;
    }

    public boolean isEnabled() {
        return ((status != null) && !status.equals(STATUS_DISABLED));
    }

    /** * @param enabled boolean. */
    public void setEnabled(boolean enabled) {
        if (enabled) {
            status = STATUS_ENABLED;
        } else {
            status = STATUS_DISABLED;
        }
    }
}
